package com.speech.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.speech.R;
import com.speech.item.MissionNoobListViewItem;

import java.util.List;

public class MissionNoobListViewAdapter extends BaseAdapter {

    private List<MissionNoobListViewItem> mLst;
    private Context mContext;

    public MissionNoobListViewAdapter(List<MissionNoobListViewItem> lstData,Context context){
        mLst = lstData;
        mContext = context;
    }

    @Override
    public int getCount() {
        return mLst.size();
    }

    @Override
    public Object getItem(int position) {
        return mLst.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView==null) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(R.layout.item_mission_noob, null);
            viewHolder = new ViewHolder();

            viewHolder.img_icon = convertView.findViewById(R.id.img_item_missionNoob_left_logo);
            viewHolder.img_state = convertView.findViewById(R.id.img_item_missionNoob_state);
            viewHolder.tv_award = convertView.findViewById(R.id.tv_item_missionNoob_award);
            viewHolder.tv_desc = convertView.findViewById(R.id.tv_item_missionNoob_desc);
            viewHolder.tv_title = convertView.findViewById(R.id.tv_item_missionNoob_title);

            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        MissionNoobListViewItem item = mLst.get(position);
        viewHolder.img_icon.setImageResource(item.iLeftIconResID);
        viewHolder.img_state.setImageResource(item.iRightIconResID);
        viewHolder.tv_title.setText(item.strTitle);
        viewHolder.tv_award.setText(item.iAward+"");
        viewHolder.tv_desc.setText(item.strDesc);

        return convertView;
    }

    class ViewHolder{
        TextView tv_title;
        TextView tv_desc;
        TextView tv_award;
        ImageView img_icon;
        ImageView img_state;
    }
}
